<?php
namespace Home\Controller;
use Think\Controller;
class BzjpController extends Controller {
    public function freeIndex(){
       //1.免费查看订单
        cookie('freeType',$_REQUEST['freeType']);

        indexRvent();//测算首页执行事件
        indexRequest($_REQUEST);//测算首页接收数据处理
        redirect(U('Bzjp/index','',false));
    }
    public function index(){
        indexRvent();//测算首页执行事件
        indexRequest($_REQUEST);//测算首页接收数据处理
        $edition=cookie('edition');//新版本
        $csCont='Bzjp';//控制器
        $randName='bzjpcs';//随机数
        if($edition==1){
            $csType='ZM071';
            $titleType='BzjpZyb';
        }else{
            $csType='JP';//订单前缀、统计标识
            $titleType='Bzjp';//头部名称标识
        }
        $this->assign('titleName',titleName($titleType,1));//标题名称

        $typeid=cookie('typeid');//八字typeid
        $channel=cookie('channel');

        indexInterface($csCont,$csType,$randName);//首页公共函数


        $channel=cookie('channel');
        if($channel=='qudao245'){
            //header('location:https://aiface.yixueqm.com/app/index.php?i=2&c=entry&do=index&m=hc_face&pid=10');exit;
        }elseif($channel=='qudao317'){
            redirect(U('Bzcy/index','',false));
        }

//        if($_REQUEST['csType']){//分享赚佣金
//            cookie('csType',$_REQUEST['csType']);
//            cookie('shareUid',$_REQUEST['shareUid']);//别人分享的链接
//
//            $ShareController=A('Share');
//            $collectionType=$ShareController->selectCollection();//是否收藏
//            $priceArr=$ShareController->shareZhuan('bzjp');//获取首页数据价格
//            cookie('pricezhuan',$priceArr['price']);
//            //dump($priceArr);exit;
//            $this->assign('priceArr',$priceArr);
//            $this->assign('collectionType',$collectionType);
//            $this->assign('discount',$_REQUEST['discount']);
//            $this->assign('csType','bzjp');
//            if($_REQUEST['shareUid']){
//                $this->assign('csTypeNum',0);
//                $this->assign("shareUidNum",1);
//            }else{
//                $this->assign('csTypeNum',1);
//                $this->assign("shareUidNum",0);
//            }
//        }else if(cookie('shareUid')!=''){
//            $ShareController=A('Share');
//            $priceArr=$ShareController->shareZhuan('bzjp');//获取首页数据价格
//            $this->assign('priceArr',$priceArr);
//            $this->assign('csType','bzjp');
//            $this->assign('csTypeNum',0);
//            $this->assign("shareUidNum",1);
//        }

//        discountprice($channel);//优惠价格获取
//        if($_REQUEST['discount']){
//            cookie('discount',1);
//        }
//        $this->assign('discount',cookie('discount'));//是否优惠价格

        //渠道获取统计ID
        $channelID=obtain_channelID($csType);
        $this->assign('channelID',$channelID);

        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
            if(strpos($user_agent, 'iPhone')||strpos($user_agent, 'iPad')){//IOS端
                $phone='IOS';
                $this->assign('iphone',1);
            }else if(strpos($user_agent, 'Android')){
                $phone='Android';
            }

            if (strpos($user_agent,'Windows') == true||strpos($user_agent,'Mac') == true) {//Windows 电脑访问
                if(channelSaoma($channel)){
                    $PCType=1;
                    $this->assign('pc',$PCType);
                }
            }
        }else{
            //if($_SERVER['HTTP_HOST']=='www.tomome.cn'){
//                $wzurl='http://'.$_SERVER['HTTP_HOST'].'/zhiming/index.php/Home-Bzjp-index';
//                if(!empty($_REQUEST['code'])){
//                    cookie('code',$_REQUEST['code'],7100);
//                }
//                getToken();
//                getTicket();
//                wxGetCode($wzurl);
//                Caccess_token();
//                if($_REQUEST['openid']||cookie('openidZ')){//分享获取openid
//                    if($_REQUEST['openid']){cookie('openidZ',$_REQUEST['openid'],60);}
//                    $user=wxgetUsertext();
//                    $nickname=$user['nickname'];
//                    $openid=$user['openid'];
//                    $headimgurl=$user['headimgurl'];
//                    if($openid&&$headimgurl){
//                        $this->userWxAdd(cookie('openidZ'),$openid,$nickname,$headimgurl);
//                    }else{
//                        cookie('code',null);
//                        echo '记录失败';
//                    }
//                }
//                $noncestr=noncestr(15);
//                $timestamp=time();
//                $ticket= S('ticket');
//                $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");
//
//                $this->assign('appid',cookie('APPID'));
//                $this->assign('timestamp',$timestamp);
//                $this->assign('noncestr',$noncestr);
//                $this->assign('signature',$signature);
           // }
        }

//        if(changeZYF($channel)){//变换页面
//            $this->assign('title','周易大师一对一测算');
//            if (strpos($user_agent, 'MicroMessenger') == false) {
//                //非微信浏览器访问
//                $ipAddr=$_SERVER['REMOTE_ADDR'];
//            }else{
//                $ipAddr=cookie('uid');
//            }
//            $date=date('Y-m-d');
//            if(cookie($ipAddr)==''){
//                cookie($ipAddr,$date);
//                cookie('ZYF',null);
//            }else{
//                $toDay=strtotime($date);
//                $oldDay=strtotime(cookie($ipAddr));
//                $time=$toDay-$oldDay;
//                if($time>1){//一天86400秒
//                    cookie('ZYF',1);
//                }else{
//                    cookie('ZYF',null);
//                }
//            }
//            if(cookie('ZYF')){
//                redirect(U("Lnyc/index",'',false));exit;
//            }
//        }else{
//            $this->assign('title','八字精批');cookie('ZYF',null);
//        }


        //卦辞
//        $guaciArr=guaci();//卦辞
//        $guaci=guacijieshi($guaciArr['guaciJX']);
//        $arrbengua=$guaciArr['arrbengua'];
//        $arrbiangua=$guaciArr['arrbiangua'];
//        $arrliushou=$guaciArr['arrliushou'];
//        $guaxiang=$guaciArr['guaxiang'];
//        $bianguagx=$guaciArr['bianguagx'];
//
//        $this->assign('guaci',$guaci);
//        $this->assign('form',U('Bzjp/bzjp_zhifu','',false));
//        $this->assign('arrbengua',$arrbengua);//本卦
//        $this->assign('arrbiangua',$arrbiangua);//变卦
//        $this->assign('arrliushou',$arrliushou);//六兽
//        $this->assign('benguagx',$guaxiang);//本卦卦象
//        $this->assign('bianguagx',$bianguagx);//变卦卦象

        $this->assign('channel',cookie('channel'));
        $this->assign('orderidnum',cookie('orderidnum'));

        if($_REQUEST['typeName']){
            cookie('typeName',$_REQUEST['typeName']);
        }
        $typeName=cookie('typeName');

//    else if(channel138($channel)){
            //随机分钟
//            for($i=1;$i<=12;$i++){$randNumArr[$i]=rand(1,5);}
//            $this->assign('randNumArr',$randNumArr);
//            $this->display("Bzjp/ZM_bazijingpi_138");
//        }

        if($edition==1){//新版本
            $this->display("Bzjp/ZM_edition1_index");
        }else if(channelZYF($channel)||cookie('ZYF')||$typeName=='ZYF'){
            $this->display("Bzjp/ZM_bazijingpi_ZYF");
        }elseif(channelCCAgzh001($channel)){
            $this->display("Bzjp/ZM_bazijingpi_CCA_gzh001");
        } elseif(channel317PC($channel)&&$PCType==1){//PC版本
            //$this->display("Bzjp/ZM_bazijingpi_138_1");
            $this->display("Bzjp/ZM_bazijingpi_317PC");
        } else if(channelVivo($channel)){
            $this->display("Bzjp/ZM_bazijingpi_vivo");
        } else if(channel138Control()||channel138Index($channel)){//梁真 最新2020-02-25
            $this->display("Bzjp/ZM_bazijingpi_138_1");
        } else if(channelCCA($channel)){
            $this->display("Bzjp/ZM_bazijingpi_CCA");
        } else if(channelLZNew($channel)){
            $this->display("Bzjp/ZM_bazijingpi_LZ_New");
        } else if(channelLZ($channel)){
            $this->display("Bzjp/ZM_bazijingpi");
        }else if($channel=='ry'){
            $this->display("Bzjp/ZM_bazijingpi_RY");
        }elseif($channel=='lz_wnl'){
            $this->display("ZM_bazijingpi_index_lz_wnl");
        }else{
            $this->display("Bzjp/ZM_bazijingpi_CYZ");
        }
    }

    public function bzjp_zhifu(){
        $edition=cookie('edition');//新版本
        $csCont='Bzjp';//控制器
        if($edition==1){$titleType='BzjpZyb';
        }else{$titleType='Bzjp';//头部名称标识
        }
        $this->assign('titleName',titleName($titleType,2));//标题名称 公共调用

        if($edition==1){
            $csType='ZM071';
            zhifuInterface($csCont,$csType,71);//支付页公共
        }else{
            $csType='JP';//订单前缀、统计标识
            zhifuInterface($csCont,$csType,0);//支付页公共

            //渠道获取统计ID
            $channelID=obtain_channelID("{$csType}-Z");
            $this->assign('channelID',$channelID);
        }


        $Ctypeid=cookie('typeid');
        if(empty($Ctypeid))$Ctypeid=0;
        if($Ctypeid>0&&$Ctypeid<67){
            $Ctypeid=0;
        }

//        $discount=cookie('discount');
//        $reducePrice=cookie('reducePrice');
//        if($discount||$reducePrice){//是否使用了优惠价格
//            $this->assign('discount',1);
//        }else{
//            $this->assign('discount',0);
//        }


        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
            $phone='';//结果页需要录入手机号码
        }else{

        }

        if($_REQUEST['birthday']==''){
            $birthday='0-2018-08-08-8';
        }else{
            $birthday=$_REQUEST['birthday'];
        }

        if($_REQUEST['username']){//提交

        }elseif($_REQUEST['JGtype']==1){//结果页跳转下单
            $zymd=cookie('zymd');
            if(cookie('JGtypeBzjp'.$zymd)){
            }else{
                cookie('orderid',null);
                cookie('JGtypeBzjp'.$zymd,1,300);
            }
        }


        //创建订单
        $hour=cookie('zhour');if($hour==''||!is_numeric($hour))$hour=0;
        //if($hour>=24){$hour=mb_substr($hour,0,1);}
        $shop=cookie('orderid');
        $znickname=cookie('znickname');if($znickname=='')$znickname='匿名';
        $zsex=cookie('zsex');if($zsex=='')$zsex=1;
        $channel=cookie('channel');
        $imei=cookie('uid');if(cookie('uid')==''){$imei=cookie('imei');}
        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        $datetype=cookie('datetype');if($datetype=='')$datetype=0;
//        $status=-1;
//        defaultPrice();//默认价格
//        channelPay($channel,'JP');//查询渠道价格

//        if(cookie('csType')!=''){//分享赚佣金价格
//            if(cookie('pricezhuan')!=''){
//                cookie('price',cookie('pricezhuan'));
//            }
//        }

//        if(cookie('couponPrice')){//是否有使用优惠券
//            cookie('price',cookie('couponPrice'));
//            $this->assign('discount',10);//优惠券价格
//        }else{
//            $this->assign('discount',0);//优惠券价格
//        }
        //是否有趣测优惠券
//        if(cookie('discountQczh')){
//            $price=cookie('price');cookie('price',$price/2);$remark='discountQczh';
//        }

        //免费订单
//        if(cookie('freeType')==1){
//            $status=2;
//        }


        if(empty($_REQUEST['ordernum'])){
//            $arrdata=M()->query("select id from sm_h5test where ordernum='{$shop}' limit 1");
//            if(empty($arrdata)){
//                $guaciJX=cookie('guaciJX');
//                M()->query("insert into sm_h5test (minute,ordernum,price,username,typeid,sex,status,datetype,year,month,day,hour,paykind,date_remark,appuserid,ip,channel,auto_send_sms,phone)values(
//                                              '{$guaciJX}','{$shop}','{$price}','{$znickname}',0,{$zsex},-1,'{$datetype}',{$y},{$m},{$d},{$hour},-1,'{$remark}','{$imei}','{$_SERVER['REMOTE_ADDR']}','{$channel}',0,'{$phone}')");
//                $IndexController=A('Index');//Index控制器
//                $IndexController->subNumber('JP');//提交订单次数统计
//            }
//            if(!cookie($_REQUEST['username'])){//返回操作
//                //更新订单
//                M()->query("update sm_h5test set username='{$znickname}',datetype='{$datetype}',year={$y},month={$m},day={$d},sex={$zsex} where ordernum='{$shop}'");
////                M()->query("update tb_user_information set emotion='{$_REQUEST['emotion']}',childrens='{$_REQUEST['childrens']}',enterprise='{$_REQUEST['enterprise']}' where orderid='{$shop}'");
//            }

//            $arrdata=S('sm_h5test|'.$shop);
//            if(empty($arrdata)){
//                $guaciJX=cookie('guaciJX');
//                $smH5testinter=array(
//                    'minute'=>$guaciJX,
//                    'ordernum'=>$shop,
//                    'price'=>$price,
//                    'username'=>$znickname,
//                    'typeid'=>$Ctypeid,
//                    'sex'=>$zsex,
//                    'createtime'=>date('Y-m-d H:i:m'),
//                    'status'=>$status,
//                    'datetype'=>$datetype,
//                    'year'=>$y,
//                    'month'=>$m,
//                    'day'=>$d,
//                    'hour'=>$hour,
//                    'remark'=>$phoneType,
//                    'date_remark'=>$remark,
//                    'appuserid'=>$imei,
//                    'ip'=>$_SERVER['REMOTE_ADDR'],
//                    'channel'=>$channel,
//                    'auto_send_sms'=>0,
//                    'place'=>0,
//                    'phone'=>$phone
//                );
//                S('sm_h5test|'.$shop,$smH5testinter,2592000);//2592000为30天
//                cacheZhiFuOrderid($shop);//支付页缓存订单操作
//
//                $IndexController=A('Index');//Index控制器
//                $IndexController->subNumber('JP');//提交订单次数统计
           // }else if(!cookie($_REQUEST['username'])){//返回操作
                //更新订单
//                $arrdata['username']=$znickname;
//                $arrdata['datetype']=$datetype;
//                $arrdata['year']=$y;
//                $arrdata['month']=$m;
//                $arrdata['day']=$d;
//                $arrdata['sex']=$zsex;
//                S('sm_h5test|'.$shop,$arrdata,2592000);//2592000为30天
           // }
        }


        if(cookie('zsex')==1){$zsex='男';}else{$zsex='女';}
        zwmp(cookie('zymd'), cookie('zhour'),$zsex,'sizhu');
        $sizhu=I('globals.sizhu');
        $bztaisui=bztaisui($sizhu);//犯太岁
        $this->assign('bztaisui',$bztaisui);
        $this->assign('sizhu',$sizhu);//Z四柱

        if(changeJieguoPay($channel)){//判断渠道显示结果
            liunian(I('globals.bznianzhu'));
            $this->assign('liunian',I('globals.liunian'));//流年性格分析
            fortune(I('globals.shengxiao'),I('globals.bzrizhu'));
            $this->assign('shortcoming',I('globals.shortcoming'));//生肖缺点
            $this->assign('fortune',I('globals.fortune'));//流年财运
            $this->assign('congenital',I('globals.congenital'));//先天财运
            $this->assign('becareful',I('globals.be_careful'));//注意事项
            $this->assign('lovefenxi',I('globals.lovefenxi'));//爱情分析
            $liunian=I('globals.liunian');
            wuxing_healthy(mb_substr($liunian['ny'],2,1,'utf-8'));
            $this->assign('wuxing',I('globals.wuxing'));//健康五行
            wuxing_healthy(I('globals.xiys'));
            $this->assign('cause',I('globals.wuxing'));//事业喜用神

            $zhanxing=new \Library\ZhanXing();
            $constellation=$zhanxing->constellation($m,$d);//获取星座
            $cArr2019=yunshi2019($constellation);//2019运势
            $this->assign('cArr2019',$cArr2019);
        }

        if(cookie('channel')=='qudao19'){
            $this->assign('title','周易大师一对一测算');
        }else{
            $this->assign('title','八字精批');
        }

        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            if (strpos($user_agent,'Windows') == true||strpos($user_agent,'Mac') == true) {
                //Windows 电脑访问
                if(channelSaoma($channel)){
                    $PCType=1;
                    $this->assign('pc',$PCType);
                    $saomaUrl=wxsaoma('JP','八字精批',cookie('orderid'));//微信扫码回调参数
                    $this->assign('wxsaoma',$saomaUrl);
                }
            }
        }else{
            if($edition==1){
                $xml=wxgzhzf($csType,'八字精批专业版',cookie('orderid'));//公众号支付回调参数
            }else{
                if($Ctypeid>0){
                    $xml=wxgzhzf($csType.$Ctypeid,'八字精批',cookie('orderid'));//公众号支付回调参数
                }else{
                    $xml=wxgzhzf($csType,'八字精批',cookie('orderid'));//公众号支付回调参数
                }
            }


            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring),true);

//                if(empty($val['prepay_id'])){
//                    cookie('openid',null);
//                    cookie('APPID',null);
//                    cookie('APPSECRET',null);
//                }

            $noncestr=noncestr(15);//随机字符串
            $timestamp=time();//时间戳

            $stringA="appId=".cookie('APPID')."&nonceStr={$noncestr}&package=prepay_id={$val['prepay_id']}&signType=MD5&timeStamp={$timestamp}";
            $stringSignTemp=$stringA."&key=".cookie('wxKEY');
            $sign=strtoupper(md5($stringSignTemp));

            $this->assign('timeStamp',$timestamp);
            $this->assign('nonceStr',$noncestr);
            $this->assign('package','prepay_id='.$val['prepay_id']);
            $this->assign('signType','MD5');
            $this->assign('paySign',$sign);
            $this->assign('appId',cookie('APPID'));
        }

        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日

        $zyinli=yinli($y,$m,$d);
        if($hour>=24){
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.'未知');//阳历
        }else{
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时');//阳历
        }
        cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2]." ".mb_substr($sizhu[3],1,1,'utf-8')."时");//阴历

        if($datetype==1){
            $this->assign('datetype',"农历 ".cookie('zyinli'));
        }else{
            $this->assign('datetype',"阳历 ".cookie('zyangli'));
        }
        $dianping=DYdianping($y+$m+$d);//大运点评
        $this->assign('dianping',$dianping);

        $this->assign('znickname',cookie('znickname'));
        $this->assign('orderidnum',cookie('orderidnum'));
        $this->assign('wxlogin',cookie('wxlogin'));
        $this->assign('orderid',cookie('orderid'));

        $guaciArr=guaci();
        $guaci=guacijieshi(cookie('guaciJX'));//卦辞
        $this->assign('guaci',$guaci);

        $this->assign('csNameJump',U('Bzjp/jieguoye','',false).'?ordernum='.cookie('orderid'));//支付成功跳转地址

        $channel=cookie('channel');
        $this->assign('channel',cookie('channel'));

        $freeType=cookie('freeType');

        if($edition==1){
            $this->display("Bzjp/ZM_edition1_zhifu");
        }else if(channelZYF($channel)||cookie('ZYF')){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_ZYF");
        }elseif(channelCCAgzh001($channel)){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_CCA_gzh001");
        } elseif(channel317PC($channel)&&$PCType==1){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_317PC");
        } else if(channelVivo($channel)){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_vivo");
        } else if(channel138($channel)||channel138Index($channel)){
            $this->display("Bzjp/ZM_bazijingpi_zhifu");
        } else if(channelCCA($channel)){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_CCA");
        } else if(channelLZNew($channel)){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_LZ_New");
        } else if(channelLZ($channel)){
            $this->display("Bzjp/ZM_bazijingpi_zhifu");
        } else if($freeType==1){//免费
            $this->display("Bzjp/ZM_bazijingpi_zhifu_free");
        }elseif($channel=='ry'){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_ry");
        }elseif($channel=='lz_wnl'){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_lz_wnl");
        } elseif($channel=='qudao100'){
            $this->display("Bzjp/ZM_bazijingpi_zhifu_CCA");
        } else{
            if(changeJieguoPay($channel)){//判断渠道显示结果
                $this->display("Bzjp/ZM_bazijingpi_zhifu_JG");
            }else{
                //$this->display("Bzjp/ZM_bazijingpi_zhifu_CYZ");
                $this->display("Bzjp/ZM_bazijingpi_zhifu_CYZ_0428");
            }
        }
    }
    public function jieguoye(){
        jieguoInterface();//结果页公共函数
        $edition=cookie('edition');//新版本
        $csCont='Bzjp';//控制器
        if($edition==1){$titleType='BzjpZyb';
        }else{$titleType='Bzjp';//头部名称标识
        }
        $this->assign('titleName',titleName($titleType,3));//标题名称
        $channel=cookie('channel');
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
        }else{
//            $this->assign('wxlogin',1);
//
//            if($_SERVER['HTTP_HOST']==cookie('jieguoUrlYM')){
//
//            }else{
//                getToken();
//                getTicket();
//            }
//
//            $noncestr=noncestr(15);
//            $timestamp=time();
//            $ticket= S('ticket');
//            $wzurl=wxJsdkData();
//            $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");
//
//            $this->assign('appid',cookie('APPID'));
//            $this->assign('timestamp',$timestamp);
//            $this->assign('noncestr',$noncestr);
//            $this->assign('signature',$signature);
        }


        if(empty($_REQUEST['ordernum'])){

        }else{
            $ordernum=$_REQUEST['ordernum'];
            $this->editionUpdate($ordernum);
            $arrdata[0]=jieguoyeArrData($ordernum);
            $autoSendNum=$arrdata[0]['auto_send_sms'];
            $phone=$arrdata[0]['phone'];$this->assign('phone',$phone);
            $email=$arrdata[0]['email'];$this->assign('email',$email);
            $status=$arrdata[0]['status'];
            //if($channel=='qudao100'){
                $this->assign('phonebindNum',1);//手机绑定弹窗
                $wzurl=wxJsdkData();
                $this->assign('jgOrderUrl',$wzurl);

//                $arrdata=S('sm_h5test|'.$ordernum);
//                $arrdata['phone']='';
//            $arrdata['email']='';
//                S('sm_h5test|'.$ordernum,$arrdata,2592000);//2592000为30天
            //}

            //二次支付
            if($channel=='qudao100'){
                cookie('pricePt',0.01);
            }else{
                cookie('pricePt',5);
            }

            $kindArr=array(1=>$arrdata[0]['kind1'],2=>$arrdata[0]['kind2'],3=>$arrdata[0]['kind3']);
            cookie('kindArr',$kindArr);
            $this->assign('kindArr',$kindArr);
            if($_REQUEST['typeName']){//BZJPPT
                $this->assign('typeName',$_REQUEST['typeName']);
            }

            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            $hour=$arrdata[0]['hour'];
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('minute',$arrdata[0]['minute']);

            $sex=$arrdata[0]['sex'];
            $y=mb_substr(cookie('zymd'),0,4);//年
            $m=mb_substr(cookie('zymd'),5,2); //月
            $d=mb_substr(cookie('zymd'),8,2);//日

            $zymd= cookie('zymd');
            cookie('orderid',$arrdata[0]['ordernum']);
            cookie('Zorderid',$arrdata[0]['ordernum']);//二次支付主订单

            if(empty($channel)){
                $channel=$arrdata[0]['channel'];
            }
        }

        $edition=cookie('edition');//精批新版本

        if($channel=='ixkj'){
            $wzurl=wxJsdkData();
            $loopNum=loopSecond(cookie('orderid'));//循环读秒
            if($loopNum<120){
                $this->assign('wzurl',$wzurl);
                $this->display('Index/wait-loader');exit;
            }
        }



         if($_REQUEST['ymd']){//判断是否是接口
             $zymd=$_REQUEST['ymd'];
             cookie('zhour',$_REQUEST['hour']);
             cookie('zsex',$_REQUEST['sex']);
         }else{
             //一对一亲算下单
             $QSorder=new \Library\toolOrder();
             $wxzhifuArr=$QSorder->QSorderXD();
             if($wxzhifuArr==1){
                 $this->assign('qsPay',1);
             }else{//更新数据hu
                 if (strpos($user_agent, 'MicroMessenger') == false){
                     //非微信浏览器访问
                 }else{
                     $this->assign('timeStamp',$wxzhifuArr['timeStamp']);
                     $this->assign('nonceStr',$wxzhifuArr['nonceStr']);
                     $this->assign('package',$wxzhifuArr['package']);
                     $this->assign('signType',$wxzhifuArr['signType']);
                     $this->assign('paySign',$wxzhifuArr['paySign']);
                     $this->assign('appId',$wxzhifuArr['appId']);
                 }
             }
         }

        if(cookie('zsex')==1){
            $zsex='男';
        }else{
            $zsex='女';
        }


        zwmp($zymd,cookie('zhour'),$zsex,'zw');
        $sizhu=I('globals.sizhu');
        $shengxiao=I('globals.shengxiao');
        $rizhuss=I('globals.rizhuss');//日柱十神
        $ssarray=array();
        array_push($ssarray,implode(I('globals.nianzhuss')));
        array_push($ssarray,implode(I('globals.yuezhuss')));
        array_push($ssarray,implode(I('globals.shizhuss')));
        $xiys=I('globals.xiys');

        $zyinli=yinli($y,$m,$d);
        if($autoSendNum>=24){
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.'未知');//阳历
            cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2].' '.'未知');//阴历
            $this->assign('autoSendNum',$autoSendNum);
        }else{
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时');//阳历
            $hourName=mb_substr($sizhu['3'],1,1,'utf-8');
            cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2]."  {$hourName}时");//阴历
            $this->assign('zyinli',cookie('zyinli'));//阴历
        }

        if($edition!=1){
            if($zymd!=''){
                $this->assign('mgwz',I('globals.mgwz'));
                $this->assign('position',I('globals.position'));
                $this->assign('seespouse',I('globals.see-spouse'));
                $this->assign('ny',I('globals.ny'));
                $this->assign('wedlock',I('globals.wedlock'));
                $this->assign('jyfraction',I('globals.jyfraction'));
                $this->assign('yysex',I('globals.yysex'));
                $this->assign('wxj',I('globals.wxj'));
                $this->assign('lnlylr',I('globals.lnlylr'));
                $this->assign('shengxiao',$shengxiao);//生肖
                $this->assign('bznianzhu',I('globals.bznianzhu'));//年柱
                $this->assign('bzyuezhu',I('globals.bzyuezhu'));//月柱
                $this->assign('bzrizhu',I('globals.bzrizhu'));//日柱
                $this->assign('bzshizhu',I('globals.bzshizhu'));//时柱
                $this->assign('sizhu',I('globals.sizhu'));//Z四柱
                $this->assign('nianzhuss',$ssarray);//十神
                $this->assign('canggan',I('globals.canggan'));//藏干
                $this->assign('zhishen',I('globals.zhishen'));//支神
                $this->assign('sizhuny',I('globals.sizhuny'));//四柱纳音
                $this->assign('bzdishi',I('globals.bzdishi'));//八字地势
                $this->assign('wxsqs',I('globals.wxsqs'));//旺相休囚死
                $this->assign('xiys',$xiys);//喜用神
                $this->assign('taiyuan',I('globals.taiyuan'));//胎元
                $this->assign('rikong',I('globals.rikong'));//日空
                $this->assign('dayun',I('globals.dayun'));//大运
                $this->assign('dayunx',I('globals.dayunx'));//大运x
                $this->assign('dayuny',I('globals.dayuny'));//大运y
                $this->assign('dayungz',I('globals.dayungz'));//大运干支
                liunian(I('globals.bznianzhu'));
                $this->assign('liunian',I('globals.liunian'));//流年性格分析
                $fortuneData=fortune(I('globals.shengxiao'),I('globals.bzrizhu'));
                $this->assign('fortuneData',$fortuneData);
                $this->assign('shortcoming',I('globals.shortcoming'));//生肖缺点
                $this->assign('fortune',I('globals.fortune'));//流年财运
                $this->assign('congenital',I('globals.congenital'));//先天财运
                $this->assign('becareful',I('globals.be_careful'));//注意事项
                $this->assign('lovefenxi',I('globals.lovefenxi'));//爱情分析
                $this->assign('arrtaohua',I('globals.arrtaohua'));//爱情桃花
                $this->assign('shengxiaosh',I('globals.shengxiaosh'));//生肖三合
                $liunian=I('globals.liunian');
                wuxing_healthy(mb_substr($liunian['ny'],2,1,'utf-8'));
                $this->assign('wuxing',I('globals.wuxing'));//健康五行
                $wuxing=I('globals.wuxing');
                wuxing_healthy($xiys);
                $this->assign('cause',I('globals.wuxing'));//事业喜用神

                $zhanxing=new \Library\ZhanXing();
                $constellation=$zhanxing->constellation($m,$d);//获取星座
                $cArr2019=yunshi2019($constellation);//2019运势
                $this->assign('cArr2019',$cArr2019);

                //流月运势
                $lyysData=$this->lyysData($zymd,$hour);
                $this->assign('lyysData',$lyysData);


                //紫薇
                cyzk(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
                $cyzkzx=I('globals.cyzkzx');//财运主星
                syfz(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
                $syfzzx=I('globals.syfzzx');//事业主星
                hyqg(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
                $hyqgzx=I('globals.hyqgzx');//婚姻主星
                zsqk(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'));
                $zsqkzx=I('globals.zsqkzx');//自身主星

                $ziweiFenxi=BZziweiFenxi($syfzzx,$cyzkzx,$hyqgzx,$zsqkzx);
                $this->assign('ziweiFenxi',$ziweiFenxi);

//            $guaciJX=guaciJX(cookie('minute'));//卦辞
//            $this->assign('guaciJX',$guaciJX);
            }

            //流年数据
//        $InterfaceMPController=A('InterfaceMP');//控制器
//        $lnData=$InterfaceMPController->ZWmingpan('0-'.$zymd."-{$zhour}",cookie('zsex'),'2020-01-01');
            $Lnyc2020Data=new \Library\Lnyc2020Data();
            $lnData=$Lnyc2020Data->zwlnData($zymd,cookie('zhour'));
            $this->assign('lnData',$lnData);

//        if($_REQUEST['ymd']) {//判断是否是接口
//           $selectArr=array(
//               'sizhu'=>I('globals.sizhu'),
//               'nianzhuss'=>$ssarray,
//               'canggan'=>I('globals.canggan'),
//               'zhishen'=>I('globals.zhishen'),
//               'sizhuny'=>I('globals.sizhuny'),
//               'bzdishi'=>I('globals.bzdishi'),
//               'wxsqs'=>I('globals.wxsqs'),
//               'xiys'=>I('globals.xiys'),
//               'taiyuan'=>I('globals.taiyuan'),
//               'rikong'=>I('globals.rikong'),
//               'dayun'=>I('globals.dayun'),
//               'dayunx'=>I('globals.dayunx'),
//               'dayuny'=>I('globals.dayuny'),
//               'dayungz'=>I('globals.dayungz'),
//               'zyinli'=>cookie('zyinli'),
//               'liunian'=>I('globals.liunian'),
//               'shortcoming'=>I('globals.shortcoming'),
//               'fortune'=>I('globals.fortune'),
//               'congenital'=>I('globals.congenital'),
//               'becareful'=>I('globals.be_careful'),
//               'lovefenxi'=>I('globals.lovefenxi'),
//               'arrtaohua'=>I('globals.arrtaohua'),
//               'shengxiaosh'=>I('globals.shengxiaosh'),
//               'wuxing'=>$wuxing,
//               'cause'=>I('globals.wuxing'),
//               'ziweidoushu'=>$ziweiFenxi,
//               'liuyue2018'=>liuyue2018(),
//           );
//            $json=json_encode($selectArr);
//            echo $json;
//            exit;
//        }

            //商品文案
            $shopClerk_all=S('shopClerk_all'.$shengxiao);
            if(empty($shopClerk_all)){//2020.06.03新修改商品
                $shopClerk1=M()->query("select * from shop_clerk where name='ds2' and shopName='{$shengxiao}'");
                $shopClerk1=shop_clerk($shopClerk1);
                $shopClerk_all=$shopClerk1;S('shopClerk_all'.$shengxiao,$shopClerk_all,600);
            }
            $this->assign('shopClerk_all',$shopClerk_all);

            if(cookie('channel')=='qudao19'){
                $this->assign('title','周易大师一对一测算');
            }else{
                $this->assign('title','八字精批');
            }

            $jpbm=mb_substr(cookie('Zorderid'),0,4);

            //五行性格缺失
            $dataClass=new \Library\Data();
            $wuxingXg=$dataClass->wuxingXg($sizhu,$sex);
            $this->assign('wuxingXg',$wuxingXg);
            //五行爱情分析
            $wuxingAq=$dataClass->wuxingLoveanalyse($xiys);
            $this->assign('wuxingAq',$wuxingAq);
        }else{
            $birthday="0-{$zymd}-{$hour}-00";
            $interfaceAppTool=A('InterfaceAppTool');
            $mingpanData=$interfaceAppTool->BZmingpan($birthday,$sex);
            $BzjpClass=new \Library\BzjpData();
            $JPwxbj=$BzjpClass->wxbj($xiys);//五行补救
            $JPmingG=$BzjpClass->mingGong($sizhu);//命宫
            $JPyzjlm=$BzjpClass->yzjLm($sizhu,$zyinli);//一掌经论命
            $JPrglm=$BzjpClass->rglm($sizhu);//日干论命
            $JPssxj=$BzjpClass->ssMingju($rizhuss);//十神详解
            $JPqtbj=$BzjpClass->qtbjData($sizhu);//穷通宝鉴
            $JPgsclm=$BzjpClass->gsclm($sizhu);//古诗词论命
            $JPggzlm=$BzjpClass->ggzlm($sizhu);//鬼谷子论命
            $JPsmth=$BzjpClass->smth($sizhu);//三命通会
            $JPbzzl=$BzjpClass->bzzl($zymd);//八字重量
            $JPDataArr=array(
                'JPwxbj'=>$JPwxbj,
                'JPmingG'=>$JPmingG,
                'JPyzjlm'=>$JPyzjlm,
                'JPrglm'=>$JPrglm,
                'JPssxj'=>$JPssxj,
                'JPqtbj'=>$JPqtbj,
                'JPgsclm'=>$JPgsclm,
                'JPggzlm'=>$JPggzlm,
                'JPsmth'=>$JPsmth,
                'JPbzzl'=>$JPbzzl,
                'mpData'=>$mingpanData,
            );
            //dump($JPDataArr);
            $this->assign('Arr',$JPDataArr);
        }

        $this->assign('channel',cookie('channel'));
        $this->assign('orderidnum',cookie('orderidnum'));
        $this->assign('jieguoye','jieguoye');
        $this->assign('csName','JP');

        //点击跳支付页功能
//        $jumpZhifuData=jufvmpZhifu();
//        $this->assign('jumpZhifuData',$jumpZhifuData);



        if($edition==1){//新版本
            $this->display("Bzjp/ZM_edition1_jieguoye");
        }else if(channelZYF($channel)||cookie('ZYF')){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_ZYF");
        } elseif(channel317PC($channel)){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_317PC");
        } else if(channelVivo($channel)){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_vivo");
        } else if(channel138($channel)||channel138Index($channel)){//梁真
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_138");
        } else if(channelCCA($channel)){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_CCA");
        }else if(channelLZ($channel)||channelLZNew($channel)||$jpbm=='JPBM'){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye");
        }elseif(JGchannelV1($channel)){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_ZYF");
        }else if($status==2){//免费订单
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_ZYF");
        }elseif($channel=='lz_wnl'){
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_lz_wnl");
        } else{
            $this->display("Bzjp/ZM_bazijingpi_jieguoye_PayTwo");
            //$this->display("Bzjp/ZM_bazijingpi_jieguoye_CYZ");
        }
    }
    public function  editionUpdate($ordernum){//版本状态更新
        $channel=cookie('channel');
//        if($channel=='qudao100'){
//            cookie('edition',1);return;
//        }
        $str2=substr($ordernum,0,5);
        if($str2=="ZM071"){
            cookie('edition',1);
        }else{
            cookie('edition',null);
        }
    }
    public function lyysData($zymd,$hour){//流月运势
        $MyysData=new \Library\Myys2020Data();
        $MyysArr1=$MyysData->monthly($zymd,$hour,1);
        $MyysArr2=$MyysData->monthly($zymd,$hour,2);
        $MyysArr3=$MyysData->monthly($zymd,$hour,3);
        $dataArr=array_merge(array_values($MyysArr1['textData']),array_values($MyysArr2['textData']),array_values($MyysArr3['textData']));
        foreach($dataArr as $key=>$value){
            $posNum=strpos($value,'，');
            $dataArr[$key]=substr($value,$posNum+3,500);
        }
        return $dataArr;
    }

    public function payzfEnd(){
        $this->display('Index/payzfEnd');
    }
    public function jpzhifu(){
        $this->user_clickPay();
        $data=M()->query("select status from sm_h5test where ordernum='".cookie('orderid')."'");
        $this->assign('status',$data[0]['status']);
        $this->display("Index/ZM_zzhifu");
    }
    public function pay(){

        //容错查询
        $ordernum=cookie('orderid');
        $arrdata=jieguoyeArrData($ordernum);
        $status=$arrdata['status'];
        if($status==1){redirect(U('index/mycesuan','',false));}

        $this->assign('ordername1','八字精批');
        $this->assign('ordername2','知命-八字精批');
        $this->display("Index/pay");
    }
    public function paywx(){
        $edition=cookie('edition');//新版本
        if($edition==1){
            $csType='ZM071';
        }else{
            $csType='JP';//订单前缀、统计标识
        }

        $typeid=cookie('typeid');
        if($typeid>0){
            H5ZMwxzhifu($csType.$typeid,'八字精批',cookie('orderid'),'Bzjp');//知命
        }else{
            H5ZMwxzhifu($csType,'八字精批',cookie('orderid'),'Bzjp');//知命
        }
    }

    public function user_click(){//用户点击统计
        $uid=cookie('uid');
        //$ordernum=cookie('orderid');
        $channel=cookie('channel');
        $dataArr=M()->query("select id,clickCs from tb_user_click where uid='{$uid}' and price=0 order by id desc limit 1 ");
        if(empty($dataArr)){
            M()->query("insert into tb_user_click (uid,clickPay,clickCs,source,channel,price)values(
            '{$uid}',0,1,'{$_REQUEST['name']}','{$channel}',0)");
        }else{
            M()->query("update tb_user_click set clickCs='{$dataArr[0]['clickCs']}'+1 where id='{$dataArr[0]['id']}'");
        }
    }
    public function user_clickPay(){//用户支付点击统计
        $uid=cookie('uid');
        $ordernum=cookie('orderid');
        $price=cookie('price');
        $dataArr=M()->query("select id,clickPay from tb_user_click where uid='{$uid}' order by id desc limit 1 ");
        if($dataArr){
            M()->query("update tb_user_click set clickPay='{$dataArr[0]['clickPay']}'+1,ordernum='{$ordernum}',price='{$price}' where id='{$dataArr[0]['id']}'");
        }
    }

    public function CountDown(){//倒计时
        $timeStrto=cookie('timeStrto');
        $strto=$timeStrto-time();
        $h=intval($strto/60/60);
        $i=intval(($strto-60*60*$h)/60);
        $s=($strto-60*60*$h)%60;

        $h=str_pad($h,2,'0',STR_PAD_LEFT);
        $i=str_pad($i,2,'0',STR_PAD_LEFT);
        $s=str_pad($s,2,'0',STR_PAD_LEFT);

        if($strto>0){
            $data="{$h}:{$i}:{$s}";
            echo json_encode($data);
        }else{
            $data="00:00:00";
            echo json_encode($data);
        }
    }

    public function wxShare(){//微信分享次数记录
        $date=date('Ymd');
        $channel=cookie('channel');
        $dataArr=M()->query("select id,shareNum from tb_cnzz_pvuv where date='{$date}' and channel='{$channel}' and csName='JP'");
        M()->query("update tb_cnzz_pvuv set shareNum='{$dataArr[0]['shareNum']}'+1 where id='{$dataArr[0]['id']}' and csName='JP'");
        echo json_encode($channel);
    }

    public function userWx(){//微信openid账号记录 跳转
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            if(!empty($_REQUEST['code'])){
                cookie('code',$_REQUEST['code'],7100);
            }
            getToken();
            getTicket();
            $noncestr=noncestr(15);
            $timestamp=time();
            $ticket= S('ticket');
            $wzurl=wxJsdkData();
            $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");
            $this->assign('appid',cookie('APPID'));
            $this->assign('timestamp',$timestamp);
            $this->assign('noncestr',$noncestr);
            $this->assign('signature',$signature);
            getCode($wzurl);
            getOopenid();
        }
        $openid=cookie("openid");
        if(empty($openid)){cookie('code',null);}
        $channel=cookie('channel');
        //红包分享
        if($channel!='qudao19'){
            $JPwxfxUrl="http://www.tomome.cn/zhiming/index.php/Home-Bzjp-index?channel={$channel}&openid={$openid}";
        }else{
            $JPwxfxUrl="http://www.tomome.cn/zhiming/index.php/Home-Bzjp-index?channel=qudao103&openid={$openid}";
        }
        $this->assign('JPwxfxUrl',$JPwxfxUrl);//分享地址拼接

        $userArr=M()->query("select id,price from tb_user_weixin where openid='{$openid}' or openid_qc='{$openid}'");
        if(empty($userArr)){
            if($_SERVER['HTTP_HOST']=='www.tomome.cn'){
                M()->query("insert into tb_user_weixin (price,openid_qc,channel)values(0.5,'{$openid}','{$channel}')");
            }else{
                M()->query("insert into tb_user_weixin (price,openid,channel)values(0.5,'{$openid}','{$channel}')");
            }
            $this->assign('priceHB',0.5);
        }else{
            $recordArr=M()->query("select id,price,imgurl from tb_user_wx_record where openid_z='{$openid}'");
            $this->assign('recordArr',$recordArr);
            $this->assign('priceHB',$userArr[0]['price']);
        }

        //循环时间设置
        $redBArr=M()->query("select id,text from tb_cnzz_index where type='redB'");
        $setHDTime=$redBArr[0]['text'];
        $today=time();
        $oldTime=strtotime($setHDTime);
        if($today>$oldTime){
            $newTime=strtotime('+5 day',strtotime($setHDTime));
            $setHDTime=date('Y/m/d H:i:s',$newTime);
            M()->query("update tb_cnzz_index set text='{$setHDTime}' where id='{$redBArr[0]['id']}'");
            M()->query("update tb_user_weixin set price=0.50");
        }

        $this->assign('setHDTime',$setHDTime);
        $this->display('Share/share');
    }
    public function userWxAdd($openidZ,$openid,$nickname,$headimgurl){//增加红包分享记录
       $userWxArr=M()->query("select id from tb_user_wx_record where openid='{$openid}'");
        $channel=cookie('channel');
        if(empty($userWxArr)&&$openidZ!=$openid){
            $rand=mt_rand(10,25);
            $priceZ='0.'.$rand;
            M()->query("insert into tb_user_wx_record (price,name,imgurl,openid,openid_z)values(
                                                        {$priceZ},'{$nickname}','{$headimgurl}','{$openid}','{$openidZ}')");
            $userZarr=M()->query("select id,price from tb_user_weixin where openid='{$openidZ}' or openid_qc='{$openidZ}' limit 1");
            $price=$userZarr[0]['price']+$priceZ;
            M()->query("update tb_user_weixin set price='{$price}' where id='{$userZarr[0]['id']}' ");
        }
    }
    public function tixianUrl(){//提现操作关注公众号
        if($_SERVER['HTTP_HOST']=='www.tomome.cn'){
            if($_REQUEST['userId']){
              cookie('userId',$_REQUEST['userId']);
                cookie('code',null);
            }
            getToken();
            getTicket();
            $wzurl=wxJsdkData();
            if(!empty($_REQUEST['code'])){
                cookie('code',$_REQUEST['code'],7100);
            }
            wxGetCode($wzurl);
            Caccess_token();
            if(cookie('userId')){
                $userId=cookie('userId');
                $openid=cookie('openid');
                if(empty($openid)){
                    echo 'openid获取失败';exit;
                }
                M()->query("update tb_user_weixin set openid_qc='{$openid}' where id='{$userId}'");
                cookie('userId',null);
            }

            header("location:https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzUyNjY0Njk1Mw==&scene=116#wechat_redirect");
        }else{
            $openid=cookie("openid");
            $userArr=M()->query("select id,price from tb_user_weixin where openid='{$openid}'");
            if($userArr[0]['id']){
                header("location:http://www.tomome.cn/zhiming/index.php/Home-Bzjp-tixianUrl?userId={$userArr[0]['id']}");
            }else{
                echo 'openid记录出错';
            }

        }
    }

    public function hongbaoTX(){//微信红包提现
        if(!empty($_REQUEST['code'])){
            cookie('code',$_REQUEST['code'],7100);
        }
        $wzurl=wxJsdkData();
        wxGetCode($wzurl);
        Caccess_token();
        $orderid='HB'.date('Ymd').mt_rand(10000,99999).date('His');//生成订单
        $openid=cookie('openid');
        $price=100;
        $noncestr=noncestr(15);
        $MCHID=C('GMCHID');
        $act_name='分享红包活动';
        $remark='分享获取红包';
        $send_name='知命趣测';
        $wishing='感谢您参加红包分享活动！';
        $appid=cookie('APPID');
        $stringA="act_name={$act_name}&client_ip={$_SERVER['REMOTE_ADDR']}&mch_billno={$orderid}&mch_id={$MCHID}&nonce_str={$noncestr}&re_openid={$openid}&remark={$remark}&send_name={$send_name}&total_amount={$price}&total_num=1&wishing={$wishing}&wxappid={$appid}";
        $stringSignTemp=$stringA."&key=".cookie('wxKEY'); //注：key为商户平台设置的密钥key
        $sign=strtoupper(md5($stringSignTemp));

        $strData=array(
            'act_name'=>$act_name,
            'client_ip'=>$_SERVER['REMOTE_ADDR'],
            'mch_billno'=>$orderid,
            'mch_id'=>$MCHID,
            'nonce_str'=>$noncestr,
            're_openid'=>$openid,
            'remark'=>$remark,
            'send_name'=>$send_name,
            'total_amount'=>$price,
            'total_num'=>1,
            'wishing'=>$wishing,
            'wxappid'=>$appid,
            'sign'=>$sign
        );
        $xml = "<xml>";
        foreach ($strData as $key=>$val)//数组转xml
        {
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        $strData=$xml;
        //$json=json_encode($data,JSON_UNESCAPED_UNICODE);
        $headers=array(
            'Content-Type:text/xml;charset=utf-8',
        );
        $APIroute=mb_substr(THINK_PATH,0,-9);
        $url="https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";

        $userZarr=M()->query("select id,price,pay_tx_number from tb_user_weixin where openid='{$openid}' or openid_qc='{$openid}' limit 1");
        if($userZarr[0]['price']<10||empty($userZarr)){
            echo '不足10元无法提现';
            header("location:https://hy.yixueqm.com/zhiming/index.php/Home-Bzjp-userWx");exit;
        }else if($userZarr[0]['pay_tx_number']>=1){
            echo '已提现过，无法重复提现';exit;
        }

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
        curl_setopt($ch,CURLOPT_URL,$url); //设置请求地址

        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM'); //默认格式为PEM，可以注释
        curl_setopt($ch,CURLOPT_SSLCERT,$APIroute.'hongbao/apiclient_cert.pem');
        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM'); //默认格式为PEM，可以注释
        curl_setopt($ch,CURLOPT_SSLKEY,$APIroute.'hongbao/apiclient_key.pem');

        curl_setopt($ch,CURLOPT_POST,true); //post请求
        curl_setopt($ch,CURLOPT_POSTFIELDS,$strData);// post请求的数据
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//不需要证书验证
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//不直接输出到页面
        $json = curl_exec($ch);
        $xmlstring = simplexml_load_string($json, 'SimpleXMLElement', LIBXML_NOCDATA);
        $val = json_decode(json_encode($xmlstring),true);
        if($val['result_code']=='SUCCESS'){
           $reduceP=$price/100;
            M()->query("update tb_user_weixin set price='{$userZarr[0]['price']}'-{$reduceP},pay_tx_number=1 where id='{$userZarr[0]['id']}'");
            $this->assign("TXprice",$reduceP);
            $this->display("Share/putend");//提现成功提示页面
        }else{
            dump($val);
        }
    }
    public function putend(){//提现成功提示页面
        $this->assign("TXprice",1);
        $this->display("Share/putend");
    }
    public function changePrice(){
        $price=$_REQUEST['price'];
        $orderid=cookie('orderid');
        $remark=$_REQUEST['remark'];
        $arrdata=S('sm_h5test|'.$orderid);
        $arrdata['price']=$price;
        $arrdata['remark']=$remark;
        cookie('price',$price);
        S('sm_h5test|'.$orderid,$arrdata,2592000);
    }

    //结果页二次支付
    public function jgPayTwo(){
        $kind=$_REQUEST['kind'];
        $kindArr=array(1=>'2020运势',2=>'每月运势',3=>'紫微运势');
        cookie('kind',$kind);
        cookie('kindName',$kindArr[$kind]);
        $this->jgOrderInsert($kind);

        //统计
        //$this->jginterfacePvuv($kind);
    }
    public function jginterfacePvuv($kind){//二次支付统计
        if($_REQUEST['kind']){
            $kind=$_REQUEST['kind'];
        }
        $channel=cookie('channel');
        $cnzzarr=array(1=>'jpKind1',2=>'jpKind2',3=>'jpKind3');
        $typeName=$cnzzarr[$kind];
        $type=cookie('cnzzTypeNum'.$kind);
        if($type){
            $type=0;
        }else{
            $type=1;cookie('cnzzTypeNum'.$kind,1);
        }
        $tjUrl="https://hy.yixueqm.com/interface/index.php/home/index/interfacPvUv?typeName={$typeName}&type={$type}&channel={$channel}";
        curlGet($tjUrl);
    }
    public function jginterfacePvuvQt(){//结果页其他按钮统计
        if($_REQUEST['kind']){$kind=$_REQUEST['kind'];}

        $typeName="jpQtKind{$kind}";
        $type=cookie('cnzzTypeNumQt'.$kind);
        if($type){
            $type=0;
        }else{
            $type=1;cookie('cnzzTypeNumQt'.$kind,1);
        }
        $tjUrl="https://hy.yixueqm.com/interface/index.php/home/index/interfacPvUv?typeName={$typeName}&type={$type}";
        curlGet($tjUrl);
    }
    public function jgOrderInsert($kind){
        $kind=cookie('kind');
        $orderid=cookie('orderidJpPt'.$kind);//获取订单号
        if(empty($orderid)){
            $orderid='BZJPPT'.date('Ymd').mt_rand(1000,9999).date('His');
            $Zorderid=cookie('Zorderid');
            $channel=cookie('channel');
            S($orderid.'Zorderid',$Zorderid,3600);
            $price=cookie('pricePt');
            $uid=cookie('uid');
            cookie('orderid',$orderid,290);
            cookie('orderidJpPt'.$kind,$orderid,290);
            M()->query("insert into sm_h5test_jp_config (ordernum,price,uid,payordernum,typeid,kind,channel)values('{$Zorderid}','{$price}','{$uid}','{$orderid}',0,'{$kind}','{$channel}')");
        }else{
            cookie('orderid',$orderid);
        }
    }
    public function jgPayPt(){
        $this->jgPayTwo();
        $kindName=cookie('kindName');

        $this->assign('ordername1',"八字精批-{$kindName}");
        $this->assign('ordername2',"知命-八字精批-{$kindName}");
        $this->display("Index/pay");
    }
    public function jgPaywxPt(){
        $this->jgPayTwo();
        $kindName=cookie('kindName');
        $csName="八字精批-{$kindName}";
        $price=cookie('pricePt');
        $orderid=cookie('orderid');

        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {//微信公众号支付
            //非微信浏览器访问
            H5ZMwxzhifu('BZJPPT',$csName,$orderid,'Bzjp');//知命
        }else{
            $jumpUrl="http://{$_SERVER['HTTP_HOST']}/zhiming/index.php/Home-Index-return_urlwx?orderid={$orderid}";//成功跳转
            $returnUrl="http://{$_SERVER['HTTP_HOST']}/zhiming/index.php/Home-Index-return_urlwx?orderid={$orderid}";//取消跳转

            $notifyUrl="http://{$_SERVER['HTTP_HOST']}/zhiming/index.php/Home-Index-notify_urlwx";
            echo "<form id='form' action='http://wx.bazijingpi.top/zhiming/index.php/Home-Interface-interfaceWechatPay' method='POST'>
               <input type='hidden'  name='orderid' value=\"{$orderid}\">
               <input type='hidden'  name='price' value=\"{$price}\">
               <input type='hidden'  name='csName' value=\"{$csName}\">
               <input type='hidden'  name='jumpUrl' value=\"{$jumpUrl}\">
               <input type='hidden'  name='returnUrl' value=\"{$returnUrl}\">
               <input type='hidden'  name='notifyUrl' value=\"{$notifyUrl}\">
               <input type='hidden'  name='getTokenType' value='kaiyun'>
            </form>
            <script type='text/javascript'>document.getElementById('form').submit()</script>"
            ;
        }
    }

    public function jgSelectLoop(){//循环查询是否支付
        $ZkindArr=cookie('kindArr');
        $ordernum=cookie('orderid');
        $arrdata[0]=jieguoyeArrData($ordernum);

        $kindArr=array(1=>$arrdata[0]['kind1'],2=>$arrdata[0]['kind2'],3=>$arrdata[0]['kind3']);
        foreach($kindArr as $key=>$value){
            if($value<=$ZkindArr[$key]){
                $data=0;
            }else{
                $ZkindArr[$key]=$value;
                cookie('kindArr',$ZkindArr);
                echo 1;exit;
            }
        }
        echo $data;
    }
}